<?php
// 获得当前未回复提问列表
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
include_once("d_getLoginInfo.php");

$select_replay = "SELECT msg_ID FROM replay_msg_infos WHERE doc_ID = '" . $doc_ID . "'";
$result_replay = mysqli_query($connect_DB, $select_replay);
if ($result_replay) {
    $doc_msgID_arr = array();
    while ($row_replay = mysqli_fetch_assoc($result_replay)) {
        $doc_msgID_arr[] = $row_replay['msg_ID'];
    }
} else {
    echo "
        <div class='nullMsg'>
            查询数据库失败" . $select_replay . "
        </div>
        ";
    $connect_DB->close();
    exit();
}

$select_msg = "SELECT * FROM msg_infos  ORDER BY msg_date DESC";
if ($result_msg = mysqli_query($connect_DB, $select_msg)) {
    if (mysqli_num_rows($result_msg) > 0) {
        $count = 0;
        while ($row_msg = mysqli_fetch_object($result_msg)) {
            if (!in_array($row_msg->msg_ID, $doc_msgID_arr)) {
                $select_user = "SELECT * FROM user_infos WHERE user_ID = '" . $row_msg->user_ID . "'";
                $result_user = mysqli_query($connect_DB, $select_user);
                if ($result_user) {
                    $row_user = mysqli_fetch_object($result_user);
                    echo "
                    <form action='d_submitReplayMsg.php' class='form'>
                        <div class='question-div'>" . $row_user->user_Name . " 发布于 " . $row_msg->msg_date . "<br>" . $row_msg->msg_content . "</div>
                        <textarea maxlength='100' minlength='5' name='replay_con' placeholder='请输入您的回复，5-100字...' required></textarea>
                        <input name='msg_ID' type='hidden' value='" . $row_msg->msg_ID . "'>
                        <button type='submit'>提交</button>
                    </form>
                    ";
                } else {
                    echo "
                    <div class='nullMsg'>
                        查询" . $row_msg->user_ID . "用户信息失败
                    </div>
                    ";
                }

            }
        }
    } else {
        echo "<div class='nullMsg'>当前暂无留言</div>";
    }
}else {
    echo "
        <div class='nullMsg'>
            查询数据库失败" . $select_msg . "
        </div>
        ";
    $connect_DB->close();
    exit();
}

$connect_DB->close();
?>